package com.tianzeculture.stagebao.activity.artist;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.activity.AgreementActivity;
import com.tianzeculture.stagebao.activity.login.LoginActivity;
import com.tianzeculture.stagebao.activity.personal.EditNickNameActivity;
import com.tianzeculture.stagebao.activity.personal.SelectJobActivity;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.bean.AllIndustryBean;
import com.tianzeculture.stagebao.bean.JobBean;
import com.tianzeculture.stagebao.bean.ResultBean;
import com.tianzeculture.stagebao.bean.User;
import com.tianzeculture.stagebao.dialog.SexDialog;
import com.tianzeculture.stagebao.net.CommonRestUsage;
import com.tianzeculture.stagebao.net.UserRestUsage;
import com.tianzeculture.stagebao.network.Request;
import com.tianzeculture.stagebao.network.enity.MSG;
import com.tianzeculture.stagebao.network.util.ToastUtil;
import com.tianzeculture.stagebao.util.StatusBarUtil;
import com.tianzeculture.stagebao.util.Util;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/6/28 0028.
 * 加入人才库
 */

public class AddTalentActivity extends BaseActivity {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvPact)
    TextView tvPact;

    @BindView(R.id.layoutRealName)
    LinearLayout layoutRealName;
    @BindView(R.id.tvRealName)
    TextView tvRealName;
    @BindView(R.id.layoutSex)
    LinearLayout layoutSex;
    @BindView(R.id.tvSex)
    TextView tvSex;
    @BindView(R.id.layoutJob)
    LinearLayout layoutJob;
    @BindView(R.id.tvJob)
    TextView tvJob;

    @BindView(R.id.btnNextStep)
    Button btnNextStep;
    @BindView(R.id.check)
    CheckBox check;


    @Request
    UserRestUsage userRestUsage = null;
    private int updateMyself = 102;//更新用户信息

    @Request
    CommonRestUsage commonRestUsage = null;
    private int industryList = 104;//工作列表
    List<AllIndustryBean> allJobList;

    @Override
    public void initUI() {
        super.initUI();
        StatusBarUtil.setWindowStatusBarColor(this, R.color.colorGray_F8);

        tvTitle.setText(getString(R.string.add_talent));
        tvPact.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        tvPact.getPaint().setAntiAlias(true);//抗锯齿
        tvPact.setText(getString(R.string.pact_talent));
        tvPact.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(AddTalentActivity.this, AgreementActivity.class));
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
//        commonRestUsage.industryList(industryList);
        initUser();
    }

    private void initUser() {
        if (Util.user == null || Util.user.getSex() == null)
            return;
        if ("1".equals(Util.user.getSex()))
            tvSex.setText("男");
        else if ("1".equals(Util.user.getSex())) {
            tvSex.setText("女");
        } else {
            tvSex.setHint("请选择");
        }

    }

    @OnClick({R.id.layoutRealName, R.id.layoutSex, R.id.layoutJob, R.id.btnNextStep})
    public void onclick(View view) {
        switch (view.getId()) {
            case R.id.layoutRealName:
                startActivityForResult(new Intent(AddTalentActivity.this, EditNickNameActivity.class), Util.CHOOSE_NICKNAME);
                break;
            case R.id.layoutSex:
                SexDialog sexDialog = new SexDialog(this);
                sexDialog.setOnSelectClickListener(new SexDialog.OnSelectClickListener() {
                    @Override
                    public void onOk(boolean isMale) {
                        if (isMale)
                            tvSex.setText("男");
                        else
                            tvSex.setText("女");
                    }

                    @Override
                    public void onCancel() {

                    }
                });
                sexDialog.show();
                break;
            case R.id.layoutJob:
                Intent intent = new Intent(AddTalentActivity.this, SelectJobActivity.class);
                startActivityForResult(intent, Util.CHOOSE_JOB);
                break;
            case R.id.btnNextStep:
                if (tvRealName.getText().toString().trim().equals("")) {
                    ToastUtil.showShort(this, "请输入您的真实姓名!");
                    return;
                } else if (tvSex.getText().toString().trim().equals("")) {
                    ToastUtil.showShort(this, "请选择性别!");
                    return;
                } else if (tvJob.getText().toString().trim().equals("")) {
                    ToastUtil.showShort(this, "请选择职业!");
                    return;
                }
                if (!check.isChecked()) {
                    ToastUtil.showShort(this, "请阅读并同意舞台宝协议！");
                    return;
                }
                User user = Util.user;
                user.setIndustry(tvJob.getText().toString().trim());
                user.setName(tvRealName.getText().toString().trim());
                user.setSex("男".equals(tvSex.getText().toString().trim()) ? "1" : "0");
//                user.setAlent("1");
                userRestUsage.updateUserInfo(updateMyself, user);
                startActivity(new Intent(AddTalentActivity.this, AddTalentDataActivity.class));
                break;
        }
    }

    @Override
    public void refreshUI(int taskId, MSG msg) {
        super.refreshUI(taskId, msg);

    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_add_talent;
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //选择职业
        if (resultCode == Util.CHOOSE_JOB) {
            String job = data.getStringExtra("JOB");
            tvJob.setText(job);
//            User user = Util.user;
//            user.setIndustry(job);
//            userRestUsage.updateUserInfo(updateMyself, user);
        } else if (resultCode == Util.CHOOSE_NICKNAME) {
            Bundle bundle = data.getExtras();
            String name = bundle.getString("NICKNAME");
            tvRealName.setText(name);
//            User user = Util.user;
//            user.setName(name);
//            userRestUsage.updateUserInfo(updateMyself, user);
        }
    }
}
